<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
	<div class="creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;客户表>鑫合汇客户附件下载列表</span>
			<a href="javascript:void(0)"></a>
		</div>

		<div class="ibox-content ibox-zxsearchqu ">
			<div class="row">
				<div class="col-xs-12 col-sm-12 col-md-12 col-lg-4">
					<div class="row">
						<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
							<label class="sr-only">客户名：</label> <input type="text"
								placeholder="客户名" id="customerName" name="customerName"
								class="form-control">
						</div>
						<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
							<label class="sr-only">身份证号码：</label> <input type="text"
								placeholder="身份证号码" id="customerNo" name="customerNo"
								class="form-control">
						</div>
					</div>
				</div>
				<div class="col-xs-12 col-sm-12 col-md-12 col-lg-3">
					<div class="row">
						<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
							<input id="submitTimeStart" name="submitTimeStart"
								placeholder="开始时间" class="laydate-icon form-control">
						</div>
						<label class="hxleft">至</label>
						<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
							<input id="submitTimeEnd" name="submitTimeEnd" placeholder="结束时间"
								class="laydate-icon form-control">
						</div>
					</div>
				</div>

				<div class="col-xs-12 col-sm-12 col-md-12 col-lg-5" id="buttonall">
					<button class="btn dpbtn_blue_null" type="button" onclick="query(0,0);">当日</button>
					<button class="btn dpbtn_blue_null" type="button" onclick="query(-1,-1);">昨日</button>
					<button class="btn dpbtn_blue_null" type="button" onclick="query(-6,0);">近7日</button>
					<button class="btn dpbtn_blue_null butactive" type="button" onclick="query(-29,0);">近30日</button>
					<button class="zhixcx-left zhixcx" type="button" onclick="query();">执行查询</button>
				</div>
			</div>
		</div>
		
		<div class="ibox-content">
			<!-- <span class="warning-label"><span class="red-dp-circle"></span>鑫合汇客户订单信息</span> -->
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>
	
	<div id="hqquery" class="hqquery" style="display: none;">
		<div class="business-padding" >
			<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
				<tr>
					<td align="right">
						<label class="control-label">客户姓名：</label>
					</td>
					<td>
						<input id="customerNameb" name="customerNameb"  class="form-control" placeholder="客户姓名" readonly="readonly" />
						<input id="idb" type="hidden" />
					</td>
				</tr>
				<tr>	
					<td align="right">
						<label class="control-label">身份证号码：</label>
					</td>
					<td>
						<input id="customerNob" name="customerNob"  class="form-control" placeholder="身份证号码" readonly="readonly" />
					</td>
				</tr>
			</table>
		</div>
		<div class="padding-nono" >
			<table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8"  width="100%">
				<tr>
					<td width="100%" align="center">
						 <div class="ibox-content">
						 	  <span id="downLoad" class=""></span>
				              <button type="button" class="btn dpbtn_grey" onclick="cancel();">取消</button>
				          </div>
					</td>
				</tr>
			</table>
		</div>	
	</div>
	
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>
	<!-- layerDate plugin javascript -->
	<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
	<script type="text/javascript">
	var startOption,endOption,fujianLayer;
	jQuery(function($) {
		//外部js调用
		startOption = {
		  elem: '#submitTimeStart', 
		  event: 'focus' ,
		  format: 'YYYY-MM-DD',
		  istime: false,
		  istoday: false,
		  choose: function(datas){
			 $('#buttonall .btn').removeClass('butactive');
		     endOption.min = datas;
		     endOption.start = datas;
		  },
		  clear:function(){
			  $('#buttonall .btn').removeClass('butactive');
			  endOption.min = '1970-01-01';
			  endOption.start = '1970-01-01';
		  }
		};
		    	
	   	 endOption = {
		  elem: '#submitTimeEnd', 
	      event: 'focus' ,
		  format: 'YYYY-MM-DD',
		  max: laydate.now(),
		  istime: false,
		  istoday: false,
		  choose: function(datas){
			$('#buttonall .btn').removeClass('butactive');
			startOption.max = datas;
		  },
		  clear:function(){
			  $('#buttonall .btn').removeClass('butactive');
			  startOption.max = '2099-12-31';
		  }
		};
	   	laydate(startOption);
	   	laydate(endOption);
	   	
		$('#submitTimeStart').val(laydate.now(-29));
		endOption.min = laydate.now(-29);
		endOption.start = laydate.now(-29);
		$('#submitTimeEnd').val(laydate.now(0));
		startOption.max = laydate.now(0);
		
		getData();
	});

	var winWidth = $('div.ibox-content').width();
	var winHeight = document.body.offsetHeight - 310;
    var getData = function() {
      var win = winWidth / 4;
	  $.jgrid.defaults.styleUI = 'Bootstrap';
	  jQuery("#table_list_1").jqGrid({
		url:'${basePath}/BaseCustomerController/xhhMultiList',
		postData:{submitTimeStart:laydate.now(-29),submitTimeEnd:laydate.now(0),},
        datatype : "json",
        colNames : [ '主键', '订单提交时间','客户姓名', '身份证号码'/* ,'下载' */],
        colModel : [
				{name: 'replaceId', index: 'B.id', hidden:true},
				{name: 'submitTime',index: 'B.submitTime',width: win,align: "center",formatter:function(a,b,c){
               	 	return formateToMinutes(a);
                }},
				{name: 'customerName',index: 'B.customerName',width: win,align: "center"},
				{name: 'customerNo',index: 'B.customerNo',width: win,align: "center"}
				/**
 				 * 打包附件操作
 				 * 1：暂无
 				 * 2: 生成中
 				 * 3：下载
 				 * 4：生成
 				 */
				/* ,
				{name: 'download',index: 'B.bankLoan',width: win,align: "center",sortable:false,formatter:function(a,b,c){
						
					var xhhoperationName = '';
					var xhhoperationType = c.xhhOperationType;
					 if(xhhoperationType == 1) {
						xhhoperationName = '<span>暂无<span>';
					 } else if(xhhoperationType == 2){
						xhhoperationName = '生成中';
					 } else if(xhhoperationType == 3){
						xhhoperationName = '<a class="btn dpbtn_red" download="' + c.xhhRarName + '" href="' + c.xhhRarOssPath + '">下载</a>';
					 } else if(xhhoperationType == 4){
						xhhoperationName = '<button type="button" class="btn dpbtn_green"  onclick="createXhhRar(\'' + c.replaceId + '\',this);">打包</button>';
					 }
               	 	return xhhoperationName;
                }} */
		  ],
          mtype : "post",
          height: winHeight,
          width:winWidth,  
          shrinkToFit:false,
          autoScroll: false,
          rowNum: 15,
          rowList: [15, 30, 45],
          viewrecords: true,
          pager: "#pager_list_1",
          hidegrid: false,
          multiselect : false,
          altRows:true,
          altclass:'someClass',
          ondblClickRow:function(rowId,v,e)
          {
        	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
        	  var busiId = rowData.replaceId;
        	  var customerName = rowData.customerName;
        	  var customerNo = rowData.customerNo;
        	  $("#idb").val(busiId);
			  $("#customerNameb").val(customerName);
			  $("#customerNob").val(customerNo);
			  $.dpAjax({
				  url:'${basePath}/BaseCustomerController/xhhDownload',
				  data:{busiId:busiId},
				  success:function(datas) {
					  var record = datas.result;
					  var xhhoperationName = '';
					  var xhhoperationType = record.xhhOperationType;
					  if(xhhoperationType == 1) {
						 xhhoperationName = '<button type="text" class="btn dpbtn_red">暂无</button>';
					  } else if(xhhoperationType == 2){
						  xhhoperationName = '<button type="text" class="btn dpbtn_green">生成中</button>';
					  } else if(xhhoperationType == 3){
						   xhhoperationName = '<a class="btn dpbtn_red line-heght-set" download="' + record.xhhRarName + '" href="' + record.xhhRarOssPath + '">下载</a>';
					  } else if(xhhoperationType == 4){
						   xhhoperationName = '<button type="button" class="btn dpbtn_green"  onclick="createXhhRar(\'' + record.busiId + '\',this);">打包</button>';
					  }
	               	  $('#downLoad').html(xhhoperationName);
		        	  fujianLayer = layer.open({
		    	    	  type: 1,
		    	    	  title: '附件下载',
		    	    	  shadeClose: true,
		    	    	  shade: 0.8,
		    	    	  skin: 'layui-layer-lan',
		    	    	  area: ['350px', '320px'],
		    	    	  content: $("#hqquery")
		        	  }); 
				  }
			  });
			  
          },
          jsonReader : {
        	  root:"result.rows",
        	  page: "result.page",
        	  total: "result.total",
        	  records: "result.records",
        	  repeatitems: false,
        	  id: "replaceId"
          },
          loadComplete:function(datas){
        	  if (datas.flag == "100100") {
                  layer.msg("查询成功!", {icon: 6, time: 1000});
                  return;
              }
        	  
        	  if(datas.flag == '100802') {
				  top.location.href = thisLoginUrl;
				  return;
			  }
        	  
              layer.msg(datas.message, {icon: 2});
          }
      });
    }

    window.onresize = function() {
    	$("#table_list_1").setGridWidth($(window).width()-80);
    }

    var query = function(start, end){
    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
    	var data = {};
    	data.customerNo = document.getElementById('customerNo').value || '';
    	data.customerName = document.getElementById('customerName').value || '';
    	if(start != null && typeof start != 'undefined') {
    		document.getElementById('submitTimeStart').value = laydate.now(start);
    		document.getElementById('submitTimeEnd').value = laydate.now(end);
    		
    		startOption.max = laydate.now(end);
    		endOption.min = laydate.now(start);
			endOption.start = laydate.now(start);
    	}
    	data.submitTimeStart = document.getElementById('submitTimeStart').value.trim();
    	data.submitTimeEnd = document.getElementById('submitTimeEnd').value.trim();
    	
    	$.extend(postData, data);
    	refresh();
    }
    
    var refresh = function() {
    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
    }
    
    function createXhhRar(busiId, obj){
		 if(!busiId || busiId == '') {
			 layer.msg('必须参数缺失', {icon: 5, time:2000});
			 return;
		 }
		 $.dpAjax({
	 		url:'${basePath}/BaseCustomerController/createXhhRar',
			data:{busiId:busiId},
			success: function(datas){
				$(obj).html('生成中');
	        }
	 	});
	 } 
    
	function cancel(){
    	layer.close(fujianLayer);
    }
</script>
</body>
</html>
